package editor.osx;

import adventure.commands.skills.ConjureItem;
import adventure.commands.skills.Skill;
import adventure.commands.skills.SkillEdit;
import adventure.commands.skills.SkillManager;
import adventure.placeable.PlaceableManagerEdit;
import java.text.NumberFormat;
import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Michael Hanns
 *
 */
public class EditorSkillView extends javax.swing.JDialog {

    private static final long serialVersionUID = -1522782237246166517L;
    private SkillManager skills;
    private int totalSkills;
    private PlaceableManagerEdit placeables;
    private WITNAFrameView parent;
    private int[][] itemsNeeded;

    /**
     * Creates new form EditorItemView
     */
    public EditorSkillView(java.awt.Frame parent, SkillManager s, PlaceableManagerEdit p) {
        super(parent, true);
        this.parent = (WITNAFrameView) parent;
        skills = s;
        placeables = p;
        initComponents();
        if (((SkillEdit) skills.getSkill(1)).getID() == 0) {
            skills.newSkill("");
        }
        fillTable();
        getSkillData(totalSkills - 1);
    }

    public void fillTable() {
        skillListTable.removeAll();

        int x = 1;
        while (((SkillEdit) skills.getSkill(x)).getID() != 0) {
            skillListTable.getModel().setValueAt(((SkillEdit) skills.getSkill(x)).getID(), x - 1, 0);
            skillListTable.getModel().setValueAt(((SkillEdit) skills.getSkill(x)).getName(), x - 1, 1);
            x++;
        }

        totalSkills = x;

        skillListTable.changeSelection(x - 1, 2, false, false);
    }

    private void selectSkill(int row) {
        if (skillListTable.getModel().getValueAt(row, 0) != null) {
            int id = parseInt(skillListTable.getModel().getValueAt(row, 0).toString());
            getSkillData(id);
        }
    }

    private void changeSkillType() {
        int id = parseInt(idBox.getText());
        Skill skillEntry = skills.getSkill(id);
        if (skillTypeCombo.getSelectedIndex() == 0) {
            itemIDBox.setEnabled(false);
            itemSpawnCombo.setEnabled(false);
            dicePerLvlBox.setEnabled(true);
            totalDiceBox.setEnabled(true);
            sidesPerDiceBox.setEnabled(true);
        } else if (skillTypeCombo.getSelectedIndex() == 1) {
            itemIDBox.setEnabled(false);
            itemSpawnCombo.setEnabled(false);
            dicePerLvlBox.setEnabled(true);
            totalDiceBox.setEnabled(true);
            sidesPerDiceBox.setEnabled(true);
        } else if (skillTypeCombo.getSelectedIndex() == 2) {
            itemIDBox.setEnabled(true);
            itemSpawnCombo.setEnabled(true);
            if (((SkillEdit) skillEntry).getType().equals("CONJUREITEM")
                    && ((ConjureItem) skillEntry).onFloor()) {
                itemSpawnCombo.setSelectedIndex(1);
                itemIDBox.setText(((ConjureItem) skillEntry).getItemID() + "");
            } else {
                itemSpawnCombo.setSelectedIndex(0);
            }

            dicePerLvlBox.setEnabled(false);
            totalDiceBox.setEnabled(false);
            sidesPerDiceBox.setEnabled(false);
        } else {
            itemIDBox.setEnabled(false);
            itemSpawnCombo.setEnabled(false);
            dicePerLvlBox.setEnabled(true);
            totalDiceBox.setEnabled(true);
            sidesPerDiceBox.setEnabled(true);
        }

        if (dicePerLvlBox.isEnabled() && dicePerLvlBox.isSelected()) {
            totalDiceBox.setEnabled(false);
        }

        setOutput(id);
        updatePreview();
    }

    private void setOutput(int id) {
        SkillEdit skill = (SkillEdit) skills.getSkill(id);
        attackFlagCombo.setSelectedIndex(skill.getAttackFlag());
        attackDescBox.setText(skill.getAttackDesc());
        String[] statFlag = {"ATK", "DEF", "INT", "SPD", "LCK"};

        if (skill.getType().equalsIgnoreCase("DAMAGETARGET")) {
            if (skill.getNumDice() > 0) {
                damageBox.setText("<target> for <" + skill.getNumDice() + "d"
                        + skill.getDiceSides() + "+" + statFlag[skill.getMainStat()]
                        + "> damage.");
            } else {
                damageBox.setText("<target> for <LVLd"
                        + skill.getDiceSides() + "+" + statFlag[skill.getMainStat()]
                        + "> damage.");
            }
        } else if (skill.getType().equalsIgnoreCase("HEALTARGET")) {
            if (skill.getNumDice() > 0) {
                damageBox.setText("<target> by <" + skill.getNumDice() + "d"
                        + skill.getDiceSides() + "+" + statFlag[skill.getMainStat()]
                        + "> damage.");
            } else {
                damageBox.setText("<target> by <LVLd"
                        + skill.getDiceSides() + "+" + statFlag[skill.getMainStat()]
                        + "> damage.");
            }
        } else if (skill.getType().equalsIgnoreCase("CONJUREITEM")) {
            damageBox.setText(placeables.getItem(parseInt(itemIDBox.getText())).getName()
                    + "!");
        }
    }

    private void updatePreview() {
        String[] statFlag = {"ATK", "DEF", "INT", "SPD", "LCK"};
        int skillType = skillTypeCombo.getSelectedIndex();
        System.out.println(skillType);

        String skillDice;
        if (dicePerLvlBox.isSelected()) {
            skillDice = "LVL";
        } else {
            skillDice = totalDiceBox.getText();
        }

        if (skillDice.length() == 0) {
            skillDice = "0";
        }

        String sidesDice = sidesPerDiceBox.getText();


        if (skillType == 0) {
            damageBox.setText("<target> for <" + skillDice + "d"
                    + sidesDice + "+" + statFlag[affilStatCombo.getSelectedIndex()]
                    + "> damage.");
        } else if (skillType == 1) {
            damageBox.setText("<target> by <" + skillDice + "d"
                    + sidesDice + "+" + statFlag[affilStatCombo.getSelectedIndex()]
                    + "> damage.");
        } else if (skillType == 2) {
            damageBox.setText(placeables.getItem(parseInt(itemIDBox.getText())).getName()
                    + ".");
        }
    }

    public void getSkillData(int row) {
        if (row > 0) {
            final SkillEdit skillEntry = (SkillEdit) skills.getSkill(row);
            idBox.setText(skillEntry.getID() + "");
            nameBox.setText(skillEntry.getName());
            descriptionBox.setText(skillEntry.getDescription());

            categoryCombo.setModel(new DefaultComboBoxModel(skills.getCategories()));
            categoryCombo.setSelectedItem(skillEntry.getCategory());

            // Synonyms
            String[] synonyms = skillEntry.getSynonyms();
            if (synonyms.length > 2) {
                String out = synonyms[1];
                for (int x = 2; x < synonyms.length; x++) {
                    out += "\n" + synonyms[x];
                }
                synonymsBox.setText(out);
            } else if (synonyms.length == 2) {
                synonymsBox.setText(synonyms[1]);
            } else {
                synonymsBox.setText("");
            }

            // Main stat
            affilStatCombo.setSelectedIndex(skillEntry.getMainStat());
            lvlLearnedBox.setText(skillEntry.levelLearned() + "");
            spCostBox.setText(skillEntry.getSpecialReq() + "");
            cooldownBox.setText(skillEntry.getCooldown() + "");
            notInCombatBox.setSelected(skillEntry.requiresConcentration());
            difficultyBox.setText(skillEntry.getDifficulty() + "");
            dicePerLvlBox.setSelected(skillEntry.isDicePerLevel());
            totalDiceBox.setText(skillEntry.getNumDice() + "");
            sidesPerDiceBox.setText(skillEntry.getDiceSides() + "");
            attackFlagCombo.setSelectedIndex(skillEntry.getAttackFlag());
            attackDescBox.setText(skillEntry.getAttackDesc());

            // Item prereqs
            itemsNeeded = new int[skillEntry.getItemsNeeded().length][2];
            for (int c = 0; c < itemsNeeded.length; c++) {
                itemsNeeded[c][0] = skillEntry.getItemsNeeded()[c][0];
                itemsNeeded[c][1] = skillEntry.getItemsNeeded()[c][1];
            }
            updateItemsNeededList();

            if (skillEntry.getType().equalsIgnoreCase("DAMAGETARGET")) {
                skillTypeCombo.setSelectedIndex(0);
                itemIDBox.setEnabled(false);
                itemSpawnCombo.setEnabled(false);
                dicePerLvlBox.setEnabled(true);
                totalDiceBox.setEnabled(true);
                sidesPerDiceBox.setEnabled(true);
            } else if (skillEntry.getType().equalsIgnoreCase("HEALTARGET")) {
                skillTypeCombo.setSelectedIndex(1);
                itemIDBox.setEnabled(false);
                itemSpawnCombo.setEnabled(false);
                dicePerLvlBox.setEnabled(true);
                totalDiceBox.setEnabled(true);
                sidesPerDiceBox.setEnabled(true);
            } else if (skillEntry.getType().equalsIgnoreCase("CONJUREITEM")) {
                skillTypeCombo.setSelectedIndex(2);
                itemIDBox.setEnabled(true);
                itemIDBox.setText(((ConjureItem) skillEntry).getItemID() + "");
                itemSpawnCombo.setEnabled(true);
                if (((ConjureItem) skillEntry).onFloor()) {
                    itemSpawnCombo.setSelectedIndex(1);
                } else {
                    itemSpawnCombo.setSelectedIndex(0);
                }
                dicePerLvlBox.setEnabled(false);
                totalDiceBox.setEnabled(false);
                sidesPerDiceBox.setEnabled(false);
            } else {
                itemIDBox.setEnabled(false);
                itemSpawnCombo.setEnabled(false);
                dicePerLvlBox.setEnabled(true);
                totalDiceBox.setEnabled(true);
                sidesPerDiceBox.setEnabled(true);
            }

            if (dicePerLvlBox.isEnabled() && dicePerLvlBox.isSelected()) {
                totalDiceBox.setEnabled(false);
            }

            setOutput(skillEntry.getID());
        }
    }

    private void updateItemsNeededList() {
        String[] itemPreReqs = new String[itemsNeeded.length];
        for (int c = 0; c < itemsNeeded.length; c++) {
            itemPreReqs[c] = itemsNeeded[c][0] + ":"
                    + placeables.getItem(itemsNeeded[c][0]).getName()
                    + " (x" + itemsNeeded[c][1] + ")";
        }
        DefaultListModel itemPreReqModel = new DefaultListModel();
        for (int c = 0; c < itemPreReqs.length; c++) {
            itemPreReqModel.add(c, itemPreReqs[c]);
        }
        itemPrereqList.setModel(itemPreReqModel);
    }

    private int parseInt(String text) {
        try {
            int i = Integer.parseInt(text);
            return i;
        } catch (NumberFormatException e) {
            return 0;
        }
    }

    private void addPreReqItemDialog() {
        String[] itemPossibles = new String[placeables.totalItems()];

        for (int c = 1; c <= itemPossibles.length; c++) {
            itemPossibles[c - 1] = placeables.getItem(c).getName();
        }

        JComboBox itemList = new JComboBox();
        itemList.setModel(new DefaultComboBoxModel(itemPossibles));
        JTextField quantityField = new JTextField(2);
        quantityField.setText("1");

        JPanel itemPanel = new JPanel();
        itemPanel.add(new JLabel("Item:"));
        itemPanel.add(itemList);
        itemPanel.add(Box.createHorizontalStrut(15)); // a spacer
        itemPanel.add(new JLabel("Quantity:"));
        itemPanel.add(quantityField);

        int result = JOptionPane.showConfirmDialog(null, itemPanel,
                "Add Prerequisite Item", JOptionPane.OK_CANCEL_OPTION);

        if (result == JOptionPane.OK_OPTION) {
            int id = itemList.getSelectedIndex() + 1;
            int quant = parseInt(quantityField.getText());
            for (int c = 0; c < itemsNeeded.length; c++) {
                if (itemsNeeded[c][0] == id) {
                    itemsNeeded[c][1] += quant;
                    updateItemsNeededList();
                    return;
                }
            }
            if (quant > 0) {
                int[][] itemsNeededNew = new int[itemsNeeded.length + 1][2];
                for (int c = 0; c < itemsNeeded.length; c++) {
                    itemsNeededNew[c][0] = itemsNeeded[c][0];
                    itemsNeededNew[c][1] = itemsNeeded[c][1];
                }
                itemsNeededNew[itemsNeeded.length][0] = id;
                itemsNeededNew[itemsNeeded.length][1] = quant;
                itemsNeeded = itemsNeededNew;
                updateItemsNeededList();
            }
        }

    }

    private void removePreReqItem(int selection) {
        if (itemsNeeded[selection][1] > 1) {
            itemsNeeded[selection][1] -= 1;
            updateItemsNeededList();
            itemPrereqList.setSelectedIndex(selection);
        } else {
            int[][] itemsNeededNew = new int[itemsNeeded.length - 1][2];
            boolean omitted = false;
            for (int c = 0; c < itemsNeededNew.length; c++) {
                if (c == selection) {
                    omitted = true;
                }
                if (!omitted) {
                    itemsNeededNew[c][0] = itemsNeeded[c][0];
                    itemsNeededNew[c][1] = itemsNeeded[c][1];
                } else {
                    itemsNeededNew[c][0] = itemsNeeded[c + 1][0];
                    itemsNeededNew[c][1] = itemsNeeded[c + 1][1];
                }
            }
            itemsNeeded = itemsNeededNew;
            
            updateItemsNeededList();
        }
    }

    private void duplicateSkill(int id) {
        if (totalSkills <= 200) {
            if (skills.getSkill(totalSkills - 1).getName().trim().length() == 0) {
                parent.printToConsole("You must specify a name for all existing skills before duplicating one!");
            } else {
                if (id > 0) {
                    System.out.println("id > 0");
                    if (skills.getSkill(id).getID() != 0) {
                        SkillEdit newSkill = (SkillEdit) skills.getSkill(id).cloneThis();
                        newSkill.setID(totalSkills);
                        skills.newSkill(newSkill);
                        fillTable();
                        getSkillData(totalSkills - 1);
                    } else {
                        parent.printToConsole("You must select an existing skill before attempting to duplicate!");
                    }
                }
            }
        } else {
            parent.printToConsole("You have reached the maximum number of skills!");
        }
    }

    private void newSkill() {
        if (totalSkills <= 200) {
            if (((SkillEdit) skills.getSkill(totalSkills - 1)).getName().trim().length() == 0) {
                parent.printToConsole("You must specify a name for all existing skills before creating a new one!");
            } else {
                skills.newSkill("DAMAGETARGET");
                fillTable();
                getSkillData(totalSkills - 1);
            }
        } else {
            parent.printToConsole("You have reached the maximum number of skills!");
        }
    }

    private void updateSkill() {
        int id = parseInt(idBox.getText());
        String name = nameBox.getText();

        if (id > 0 && name.length() > 0) {
            // Change type if necessary
            SkillEdit entry = (SkillEdit) skills.getSkill(id);

            // Get name and synonyms
            String[] syns = synonymsBox.getText().split("\n");
            String[] synsOut = new String[syns.length + 1];
            synsOut[0] = name;
            System.arraycopy(syns, 0, synsOut, 1, syns.length);

            // Get description
            String desc = descriptionBox.getText();

            // Get category
            String cat = (String) categoryCombo.getSelectedItem();
            
            // Get requires concentration (not in combat)
            boolean reqConcentration = notInCombatBox.isSelected();

            // Get dice vars
            int dice = 0;

            if (!dicePerLvlBox.isSelected()) {
                dice = parseInt(totalDiceBox.getText());
            }

            int sides = parseInt(sidesPerDiceBox.getText());
            int lvlLearned = parseInt(lvlLearnedBox.getText());
            int cooldown = parseInt(cooldownBox.getText());
            int spcost = parseInt(spCostBox.getText());
            int difficulty = parseInt(difficultyBox.getText());

            
            // Change type if needed
            if (!entry.getType().equalsIgnoreCase(skillTypeCombo.getSelectedItem().toString().replace(" ", ""))) {
                skills.changeSkillType(id, skillTypeCombo.getSelectedItem().toString().replace(" ", "").toUpperCase());
            }
            entry.setSynonyms(synsOut);
            entry.setDescription(desc);
            entry.setCategory(cat);
            entry.setMainStat(affilStatCombo.getSelectedIndex());
            entry.setLevelToLearn(lvlLearned);
            entry.setCooldown(cooldown);
            entry.setSpecialReq(spcost);
            entry.setItemsNeeded(itemsNeeded);
            entry.setRequiresConcentration(reqConcentration);
            entry.setDifficulty(difficulty);
            entry.setDice(dice, sides);
            entry.setActionFlag(attackFlagCombo.getSelectedIndex());
            entry.setAttackDesc(attackDescBox.getText());

            if (entry.getType().equals("CONJUREITEM")) {
                ((ConjureItem) entry).setItem(placeables.getItem(parseInt(itemIDBox.getText())));
                ((ConjureItem) entry).setOnFloor(itemSpawnCombo.getSelectedIndex() == 1);
            }


            fillTable();
            parent.setUnsavedChanges(true);

            parent.printToConsole("Skill " + name + " updated.");
            getSkillData(id);
        } else {
            parent.printToConsole("WARNING: Skill changes not saved. You must specify a name for the skill!");
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itemListPane = new javax.swing.JScrollPane();
        skillListTable = new javax.swing.JTable();
        nameBox = new javax.swing.JFormattedTextField();
        idBox = new javax.swing.JFormattedTextField(NumberFormat.getInstance());
        descScrollPane1 = new javax.swing.JScrollPane();
        descriptionBox = new javax.swing.JTextPane();
        idLabel = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        descriptionLabel = new javax.swing.JLabel();
        closeButton = new javax.swing.JButton();
        newSkillButton = new javax.swing.JButton();
        applyButton = new javax.swing.JButton();
        synonymsLabel = new javax.swing.JLabel();
        synsScrollPane = new javax.swing.JScrollPane();
        synonymsBox = new javax.swing.JTextArea();
        duplicateButton = new javax.swing.JButton();
        successPanel = new javax.swing.JPanel();
        totalDiceLabel1 = new javax.swing.JLabel();
        difficultyBox = new javax.swing.JFormattedTextField();
        dicePerLvlBox = new javax.swing.JCheckBox();
        dicePerLabel = new javax.swing.JLabel();
        totalDiceLabel = new javax.swing.JLabel();
        totalDiceBox = new javax.swing.JFormattedTextField();
        sidesPerDiceBox = new javax.swing.JFormattedTextField();
        sidesDiceLabel = new javax.swing.JLabel();
        notInCombatBox = new javax.swing.JCheckBox();
        notInCombatLabel = new javax.swing.JLabel();
        prereqPanel = new javax.swing.JPanel();
        lvlLearnedLabel = new javax.swing.JLabel();
        lvlLearnedBox = new javax.swing.JFormattedTextField();
        spCostLabel = new javax.swing.JLabel();
        spCostBox = new javax.swing.JFormattedTextField();
        cooldownBox = new javax.swing.JFormattedTextField();
        cooldownLabel = new javax.swing.JLabel();
        itemProduced = new javax.swing.JPanel();
        itemIdLabel = new javax.swing.JLabel();
        itemIDBox = new javax.swing.JFormattedTextField();
        itemSpawnLabel = new javax.swing.JLabel();
        itemSpawnCombo = new javax.swing.JComboBox();
        outputPanel = new javax.swing.JPanel();
        attackFlagCombo = new javax.swing.JComboBox();
        damageBox = new javax.swing.JFormattedTextField();
        attackDescBox = new javax.swing.JTextField();
        typePanel = new javax.swing.JPanel();
        skillTypeCombo = new javax.swing.JComboBox();
        affilStatLabel = new javax.swing.JLabel();
        affilStatCombo = new javax.swing.JComboBox();
        typeLabel = new javax.swing.JLabel();
        prereqItemsPanel = new javax.swing.JPanel();
        itemsScrollPane = new javax.swing.JScrollPane();
        itemPrereqList = new javax.swing.JList();
        addItemButton = new javax.swing.JButton();
        removeItemButton = new javax.swing.JButton();
        categoryCombo = new javax.swing.JComboBox();
        categoryLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Edit Skill");
        setLocationByPlatform(true);
        setResizable(false);

        skillListTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "#", "Name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        skillListTable.setToolTipText("Skill list");
        skillListTable.setColumnSelectionAllowed(true);
        skillListTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        skillListTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                skillListTableMouseClicked(evt);
            }
        });
        itemListPane.setViewportView(skillListTable);
        skillListTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        skillListTable.getColumnModel().getColumn(0).setMinWidth(10);
        skillListTable.getColumnModel().getColumn(0).setPreferredWidth(25);
        skillListTable.getColumnModel().getColumn(0).setMaxWidth(25);

        nameBox.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        nameBox.setToolTipText("Skill name");

        idBox.setEditable(false);
        idBox.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        idBox.setToolTipText("Skill number");

        descriptionBox.setToolTipText("Skill description");
        descScrollPane1.setViewportView(descriptionBox);

        idLabel.setText("ID:");

        nameLabel.setText("Name:");

        descriptionLabel.setText("Description:");

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        newSkillButton.setText("Add new..");
        newSkillButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newSkillButtonActionPerformed(evt);
            }
        });

        applyButton.setText("Apply");
        applyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyButtonActionPerformed(evt);
            }
        });

        synonymsLabel.setText("Synonyms:");

        synsScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        synonymsBox.setColumns(20);
        synonymsBox.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        synonymsBox.setRows(5);
        synonymsBox.setText("separate\nwith\nnew lines");
        synsScrollPane.setViewportView(synonymsBox);

        duplicateButton.setText("Duplicate");
        duplicateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                duplicateButtonActionPerformed(evt);
            }
        });

        successPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Success/Effectiveness:"));

        totalDiceLabel1.setText("Difficulty:");

        difficultyBox.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        difficultyBox.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                difficultyBoxCaretUpdate(evt);
            }
        });
        difficultyBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                difficultyBoxActionPerformed(evt);
            }
        });
        difficultyBox.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                difficultyBoxCaretPositionChanged(evt);
            }
        });

        dicePerLvlBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dicePerLvlBoxActionPerformed(evt);
            }
        });

        dicePerLabel.setText("One per level:");

        totalDiceLabel.setText("Total dice:");

        totalDiceBox.setText("55");
        totalDiceBox.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                totalDiceBoxCaretUpdate(evt);
            }
        });
        totalDiceBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                totalDiceBoxActionPerformed(evt);
            }
        });
        totalDiceBox.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                totalDiceBoxCaretPositionChanged(evt);
            }
        });

        sidesPerDiceBox.setText("55");
        sidesPerDiceBox.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                sidesPerDiceBoxCaretUpdate(evt);
            }
        });
        sidesPerDiceBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sidesPerDiceBoxActionPerformed(evt);
            }
        });
        sidesPerDiceBox.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                sidesPerDiceBoxCaretPositionChanged(evt);
            }
        });

        sidesDiceLabel.setText("Sides/dice:");

        notInCombatBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notInCombatBoxActionPerformed(evt);
            }
        });

        notInCombatLabel.setText("Not in combat:");

        javax.swing.GroupLayout successPanelLayout = new javax.swing.GroupLayout(successPanel);
        successPanel.setLayout(successPanelLayout);
        successPanelLayout.setHorizontalGroup(
            successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(successPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(sidesDiceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                    .addComponent(totalDiceLabel)
                    .addComponent(totalDiceLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(totalDiceBox, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
                    .addComponent(sidesPerDiceBox)
                    .addComponent(difficultyBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(dicePerLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(notInCombatLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(8, 8, 8)
                .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(notInCombatBox)
                    .addComponent(dicePerLvlBox, javax.swing.GroupLayout.Alignment.TRAILING)))
        );
        successPanelLayout.setVerticalGroup(
            successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(successPanelLayout.createSequentialGroup()
                .addGap(3, 3, 3)
                .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(totalDiceLabel1)
                        .addComponent(difficultyBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(notInCombatLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(notInCombatBox, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(totalDiceLabel)
                        .addComponent(totalDiceBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(dicePerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(dicePerLvlBox, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sidesPerDiceBox)
                    .addComponent(sidesDiceLabel)))
        );

        prereqPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Prerequisites:"));

        lvlLearnedLabel.setText("Level Learned:");

        lvlLearnedBox.setText("55");

        spCostLabel.setText("Special cost:");

        spCostBox.setText("55");

        cooldownBox.setText("55");

        cooldownLabel.setText("Cooldown:");

        javax.swing.GroupLayout prereqPanelLayout = new javax.swing.GroupLayout(prereqPanel);
        prereqPanel.setLayout(prereqPanelLayout);
        prereqPanelLayout.setHorizontalGroup(
            prereqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(prereqPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(prereqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lvlLearnedLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(spCostLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cooldownLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addGroup(prereqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(spCostBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lvlLearnedBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cooldownBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );
        prereqPanelLayout.setVerticalGroup(
            prereqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(prereqPanelLayout.createSequentialGroup()
                .addGap(3, 3, 3)
                .addGroup(prereqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lvlLearnedBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lvlLearnedLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(prereqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(spCostLabel)
                    .addComponent(spCostBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(prereqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cooldownBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cooldownLabel))
                .addGap(0, 8, Short.MAX_VALUE))
        );

        itemProduced.setBorder(javax.swing.BorderFactory.createTitledBorder("Item Conjured:"));

        itemIdLabel.setText("Item ID:");

        itemIDBox.setText("55");
        itemIDBox.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                itemIDBoxCaretUpdate(evt);
            }
        });

        itemSpawnLabel.setText("Item spawns:");

        itemSpawnCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Inventory", "Room" }));

        javax.swing.GroupLayout itemProducedLayout = new javax.swing.GroupLayout(itemProduced);
        itemProduced.setLayout(itemProducedLayout);
        itemProducedLayout.setHorizontalGroup(
            itemProducedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itemProducedLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(itemIdLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(itemIDBox, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(itemSpawnLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(itemSpawnCombo, 0, 212, Short.MAX_VALUE)
                .addContainerGap())
        );
        itemProducedLayout.setVerticalGroup(
            itemProducedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itemProducedLayout.createSequentialGroup()
                .addGroup(itemProducedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(itemIdLabel)
                    .addComponent(itemIDBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(itemSpawnLabel)
                    .addComponent(itemSpawnCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 6, Short.MAX_VALUE))
        );

        outputPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Output:"));

        attackFlagCombo.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
        attackFlagCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "You", "Your", "<none>" }));

        damageBox.setEditable(false);
        damageBox.setText("<target> for 5d3+INT damage!");
        damageBox.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N

        attackDescBox.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
        attackDescBox.setText("<attack description>");

        javax.swing.GroupLayout outputPanelLayout = new javax.swing.GroupLayout(outputPanel);
        outputPanel.setLayout(outputPanelLayout);
        outputPanelLayout.setHorizontalGroup(
            outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, outputPanelLayout.createSequentialGroup()
                .addContainerGap(9, Short.MAX_VALUE)
                .addComponent(attackFlagCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(attackDescBox, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(damageBox, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        outputPanelLayout.setVerticalGroup(
            outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(attackFlagCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(damageBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(attackDescBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        typePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Skill:"));

        skillTypeCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Damage Target", "Heal Target", "Conjure Item" }));
        skillTypeCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                skillTypeComboActionPerformed(evt);
            }
        });

        affilStatLabel.setText("Affiliated Stat:");

        affilStatCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Attack", "Defence", "Intelligence", "Speed", "Luck" }));
        affilStatCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                affilStatComboActionPerformed(evt);
            }
        });

        typeLabel.setText("Type:");

        javax.swing.GroupLayout typePanelLayout = new javax.swing.GroupLayout(typePanel);
        typePanel.setLayout(typePanelLayout);
        typePanelLayout.setHorizontalGroup(
            typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(skillTypeCombo, 0, 152, Short.MAX_VALUE)
            .addComponent(affilStatCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(typePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(typeLabel)
                    .addComponent(affilStatLabel))
                .addContainerGap())
        );
        typePanelLayout.setVerticalGroup(
            typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(typePanelLayout.createSequentialGroup()
                .addGap(3, 3, 3)
                .addComponent(typeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(skillTypeCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(affilStatLabel)
                .addGap(4, 4, 4)
                .addComponent(affilStatCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        prereqItemsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Prerequisites (Items):"));

        itemsScrollPane.setMaximumSize(new java.awt.Dimension(181, 140));
        itemsScrollPane.setMinimumSize(new java.awt.Dimension(181, 140));
        itemsScrollPane.setPreferredSize(new java.awt.Dimension(181, 140));

        itemPrereqList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        itemPrereqList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        itemsScrollPane.setViewportView(itemPrereqList);

        addItemButton.setText("Add");
        addItemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addItemButtonActionPerformed(evt);
            }
        });

        removeItemButton.setText("Remove");
        removeItemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeItemButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout prereqItemsPanelLayout = new javax.swing.GroupLayout(prereqItemsPanel);
        prereqItemsPanel.setLayout(prereqItemsPanelLayout);
        prereqItemsPanelLayout.setHorizontalGroup(
            prereqItemsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(prereqItemsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(itemsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(prereqItemsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(addItemButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(removeItemButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, 0))
        );
        prereqItemsPanelLayout.setVerticalGroup(
            prereqItemsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(prereqItemsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(prereqItemsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(itemsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(prereqItemsPanelLayout.createSequentialGroup()
                        .addComponent(addItemButton)
                        .addGap(0, 0, 0)
                        .addComponent(removeItemButton)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        categoryCombo.setEditable(true);

        categoryLabel.setText("Category:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(itemListPane, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(idLabel)
                                .addGap(18, 18, 18))
                            .addComponent(idBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nameLabel)
                            .addComponent(nameBox, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(categoryLabel)
                                .addGap(68, 68, 68))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(categoryCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(synonymsLabel)
                            .addComponent(synsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(descriptionLabel)
                            .addComponent(descScrollPane1)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(newSkillButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(duplicateButton))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(closeButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(applyButton))
                                .addComponent(itemProduced, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(outputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(prereqPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(successPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(prereqItemsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(11, 11, 11))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(itemListPane)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(idLabel)
                            .addComponent(nameLabel)
                            .addComponent(categoryLabel))
                        .addGap(3, 3, 3)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nameBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(idBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(categoryCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(synonymsLabel)
                            .addComponent(descriptionLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(synsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(descScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(successPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(prereqItemsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(prereqPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(itemProduced, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(outputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(newSkillButton)
                            .addComponent(duplicateButton)
                            .addComponent(closeButton)
                            .addComponent(applyButton))
                        .addGap(6, 6, 6))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void skillListTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_skillListTableMouseClicked
        int row = skillListTable.getSelectedRow();

        selectSkill(row);
    }//GEN-LAST:event_skillListTableMouseClicked

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        dispose();
    }//GEN-LAST:event_closeButtonActionPerformed

    private void newSkillButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newSkillButtonActionPerformed
        newSkill();
    }//GEN-LAST:event_newSkillButtonActionPerformed

    private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
        updateSkill();
    }//GEN-LAST:event_applyButtonActionPerformed

    private void dicePerLvlBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dicePerLvlBoxActionPerformed
        totalDiceBox.setEnabled(!dicePerLvlBox.isSelected());
        updatePreview();
    }//GEN-LAST:event_dicePerLvlBoxActionPerformed

    private void skillTypeComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skillTypeComboActionPerformed
        changeSkillType();
    }//GEN-LAST:event_skillTypeComboActionPerformed

    private void duplicateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_duplicateButtonActionPerformed
        int id = parseInt(idBox.getText());

        duplicateSkill(id);
    }//GEN-LAST:event_duplicateButtonActionPerformed

    private void affilStatComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_affilStatComboActionPerformed
        updatePreview();
    }//GEN-LAST:event_affilStatComboActionPerformed

    private void sidesPerDiceBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sidesPerDiceBoxActionPerformed
        updatePreview();
    }//GEN-LAST:event_sidesPerDiceBoxActionPerformed

    private void totalDiceBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_totalDiceBoxActionPerformed
        updatePreview();
    }//GEN-LAST:event_totalDiceBoxActionPerformed

    private void totalDiceBoxCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_totalDiceBoxCaretPositionChanged
        updatePreview();
    }//GEN-LAST:event_totalDiceBoxCaretPositionChanged

    private void sidesPerDiceBoxCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_sidesPerDiceBoxCaretPositionChanged
        updatePreview();
    }//GEN-LAST:event_sidesPerDiceBoxCaretPositionChanged

    private void totalDiceBoxCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_totalDiceBoxCaretUpdate
        updatePreview();
    }//GEN-LAST:event_totalDiceBoxCaretUpdate

    private void sidesPerDiceBoxCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_sidesPerDiceBoxCaretUpdate
        updatePreview();
    }//GEN-LAST:event_sidesPerDiceBoxCaretUpdate

    private void itemIDBoxCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_itemIDBoxCaretUpdate
        updatePreview();
    }//GEN-LAST:event_itemIDBoxCaretUpdate

    private void difficultyBoxCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_difficultyBoxCaretUpdate
        // TODO add your handling code here:
    }//GEN-LAST:event_difficultyBoxCaretUpdate

    private void difficultyBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_difficultyBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_difficultyBoxActionPerformed

    private void difficultyBoxCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_difficultyBoxCaretPositionChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_difficultyBoxCaretPositionChanged

    private void addItemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addItemButtonActionPerformed
        addPreReqItemDialog();
    }//GEN-LAST:event_addItemButtonActionPerformed

    private void removeItemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeItemButtonActionPerformed
        int selection = itemPrereqList.getSelectedIndex();
        if (selection > -1) {
            removePreReqItem(selection);
        }
    }//GEN-LAST:event_removeItemButtonActionPerformed

    private void notInCombatBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notInCombatBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_notInCombatBoxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addItemButton;
    private javax.swing.JComboBox affilStatCombo;
    private javax.swing.JLabel affilStatLabel;
    private javax.swing.JButton applyButton;
    private javax.swing.JTextField attackDescBox;
    private javax.swing.JComboBox attackFlagCombo;
    private javax.swing.JComboBox categoryCombo;
    private javax.swing.JLabel categoryLabel;
    private javax.swing.JButton closeButton;
    private javax.swing.JFormattedTextField cooldownBox;
    private javax.swing.JLabel cooldownLabel;
    private javax.swing.JFormattedTextField damageBox;
    private javax.swing.JScrollPane descScrollPane1;
    private javax.swing.JTextPane descriptionBox;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JLabel dicePerLabel;
    private javax.swing.JCheckBox dicePerLvlBox;
    private javax.swing.JFormattedTextField difficultyBox;
    private javax.swing.JButton duplicateButton;
    private javax.swing.JFormattedTextField idBox;
    private javax.swing.JLabel idLabel;
    private javax.swing.JFormattedTextField itemIDBox;
    private javax.swing.JLabel itemIdLabel;
    private javax.swing.JScrollPane itemListPane;
    private javax.swing.JList itemPrereqList;
    private javax.swing.JPanel itemProduced;
    private javax.swing.JComboBox itemSpawnCombo;
    private javax.swing.JLabel itemSpawnLabel;
    private javax.swing.JScrollPane itemsScrollPane;
    private javax.swing.JFormattedTextField lvlLearnedBox;
    private javax.swing.JLabel lvlLearnedLabel;
    private javax.swing.JFormattedTextField nameBox;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JButton newSkillButton;
    private javax.swing.JCheckBox notInCombatBox;
    private javax.swing.JLabel notInCombatLabel;
    private javax.swing.JPanel outputPanel;
    private javax.swing.JPanel prereqItemsPanel;
    private javax.swing.JPanel prereqPanel;
    private javax.swing.JButton removeItemButton;
    private javax.swing.JLabel sidesDiceLabel;
    private javax.swing.JFormattedTextField sidesPerDiceBox;
    private javax.swing.JTable skillListTable;
    private javax.swing.JComboBox skillTypeCombo;
    private javax.swing.JFormattedTextField spCostBox;
    private javax.swing.JLabel spCostLabel;
    private javax.swing.JPanel successPanel;
    private javax.swing.JTextArea synonymsBox;
    private javax.swing.JLabel synonymsLabel;
    private javax.swing.JScrollPane synsScrollPane;
    private javax.swing.JFormattedTextField totalDiceBox;
    private javax.swing.JLabel totalDiceLabel;
    private javax.swing.JLabel totalDiceLabel1;
    private javax.swing.JLabel typeLabel;
    private javax.swing.JPanel typePanel;
    // End of variables declaration//GEN-END:variables
}
